package com.qiguliuxing.dts.wx.util;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.qiguliuxing.dts.core.util.DESEncryUtils;

import java.util.Map;

/**
 * @author ww
 * @Description: 微信订单号加密
 * @date 2017/11/2 15:22
 */
public class WxPayEncryUtils {

    private final static String DES_KEY = "1qaz2w$#";

    public static String encodeAttach(Map<String,Object> params) throws Exception{
        if(params != null){
            params.put("t",System.currentTimeMillis());
            return DESEncryUtils.encryptBasedDes(JSON.toJSONString(params), DES_KEY);
        }
        return null;
    }

    public static String decodeAttach(String str) throws Exception{
        return DESEncryUtils.decryptBasedDes(str, DES_KEY);
    }

//    public static void main(String[] args){
//        try {
//            Map<String,Object> params = Maps.newHashMap();
//            params.put("module","WSLR");
//            params.put("type","pay");
//            String enStr = WxPayEncryUtils.encodeAttach(params);
//            System.out.println(enStr);
//            String edStr = WxPayEncryUtils.decodeAttach(enStr);
//            System.out.println(edStr);
//        }catch (Exception e){
//            System.out.println(e);
//        }
//
//    }
}
